clear
set more off


foreach cohort in /*20*/ 30{

*Get data, limit down to sample and relevant variables
*Already limited to individuals in the age range

use $tempdir/panel_trends_`cohort'yr_income_sdx.dta, clear
keep if race==1
keep serial pernum statefip datanum region_birth_coarse spouseregion_birth_coarse firstsoundex year1 year2 statefip spousefirstsoundex bpl spousebpl urban age spouseage agegap sex race spouserace /*
*/ married ever_married logocc* qtl* husboccscore byname_* mbpl fbpl

*Generate the absolute difference in spousal income and an individual-level measure of assortativeness
*If statements to make sure we only generate this when both spouses are white and in the age range
*Add different measures of the distance here

foreach var in $incvars{

replace logocc`var'_father_spouse = . if spouseage < `cohort' & spouseage > (`cohort' + 15)
replace logocc`var'_father_reg_spouse = . if spouseage < `cohort' & spouseage > (`cohort' + 15)

gen absdiff_`var' = abs(logocc`var'_father - logocc`var'_father_spouse) if spouserace == 1 & spouseage >= `cohort' & spouseage <= (`cohort' + 15)
gen absdiff_`var'_reg = abs(logocc`var'_father_reg - logocc`var'_father_reg_spouse) if spouserace == 1 & spouseage >= `cohort' & spouseage <= (`cohort' + 15)

}

sort year2 statefip datanum serial pernum

*Save dataset
save ${tempdir}/panelreg_inddata_`cohort'yr_sdx.dta, replace

}










